#include "editads.h"
#include "ui_editads.h"
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlDriver>

EditAds::EditAds(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::EditAds)
{
    ui->setupUi(this);
}

EditAds::~EditAds()
{
    delete ui;
}

void EditAds::on_addButton_clicked()
{
    /*QSqlQuery query;
        query.prepare("INSERT INTO \"Real_estate\" (\"Type_of_rent\", \"Rooms\", \"Area\", \"Price\", \"Phone\", \"image\") "
            "VALUES (:Type, :Rooms, :Area, :Price, :Phone, :image)");
        query.bindValue(":Title", ui->titlelineEdit->text());
        query.bindValue(":Price", ui->priceSpinBox->value());
        query.bindValue(":Description", ui->descriptionplainTextEdit->toPlainText());
        if(ui->typecomboBox->currentText()=="Дом")
            query.bindValue(":type_of_rent_id", 1);
        else if (ui->typecomboBox->currentText()=="Квартира")
            query.bindValue(":type_of_rent_id", 2);
        else if (ui->typecomboBox->currentText()=="Ангар")
            query.bindValue(":type_of_rent_id", 3);
        else
            query.bindValue(":type_of_rent_id", 4);
        query.exec();*/
}


void EditAds::on_pushButton_clicked()
{
    QString filename = QFileDialog::getOpenFileName(nullptr, "Выберите файл", ".", "Изображение (*.jpeg *.png *.jpga *.jpg)");
    QFile* imageFile = new QFile(filename);
    ui->ImageAdsSelector->setPixmap(filename);
    imageFile->open(QIODevice::ReadOnly);
    imageByte = imageFile->readAll();
    imageFile->close();
    delete imageFile;
}

